import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:home_box/pages/medicine/MedicineV/widgets/add_picture.dart';
import 'package:home_box/pages/medicine/MedicineV/widgets/medicine_info.dart';
import 'package:home_box/pages/medicine/MedicineVM/medicine_add_vm.dart';
import 'package:home_box/widgets/header.dart';

class AddMedicine extends StatefulWidget {
  const AddMedicine({super.key});

  @override
  State<AddMedicine> createState() => _AddMedicineState();
}

class _AddMedicineState extends State<AddMedicine> {
  @override
  void initState() {
    super.initState();
    Get.put(MedicineVM(), tag: 'MedicineVM');
  }

  @override
  dispose(){
    Get.delete<MedicineVM>(tag: 'MedicineVM');
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Colors.white,
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                ///顶部
                GetBuilder<MedicineVM>(
                  tag: 'MedicineVM',
                  builder: (controller) {
                    return Header(
                      showLeft: true,
                      middleText: "新增药品",
                      rightText: '保存',
                      showRight: true,
                      rightCallBack: () {
                        controller.addMedicine().then((state) {
                          if (state > 0) {
                            Get.back();
                          }
                        });
                      },
                    );
                  },
                ),

                ///添加图片
                AddPicture(),

                ///添加药品信息
                MedicineInfo(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
